<?php
namespace api\web\middleware;

// 中间件
use think\facade\Db;

class ApiLog
{
    public function handle($request, \Closure $next)
    {
        // 记录 API 请求日志
        Db::name('api_request_log')->insert([
            'api_url' => $request->domain().$request->url(),
            'request_method' => $request->method(),
            'request_ip' => $request->ip(),
            'request_time' => date('Y-m-d H:i:s'),
        ]);
        return $next($request);
    }
}